package com.seteam.collabcrossword.messages.generic;

import com.seteam.collabcrossword.CollabCrosswordUtils;
import com.seteam.collabcrossword.Globals;
import com.seteam.collabcrossword.Tile;
import com.seteam.collabcrossword.exceptions.TileException;
import com.seteam.collabcrossword.messages.Message;

import java.io.Serializable;

/**
 * Both the client and the server use this message to send letter updates.
 * The server uses received updates to change the current state that it maintains.
 * It also sends the same to the other client.
 * <p/>
 * The client uses this to show updates in real-time
 */
public class UpdateLetter implements Serializable, Message {
    private static final long serialVersionUID = -6827176523892531575L;
    private Tile tile;

    /**
     * Constructor
     *
     * @param tile the instance of {@link Tile} that contains an updated letter
     * @throws TileException if the value passed is null
     */
    public UpdateLetter(final Tile tile) throws TileException {
        CollabCrosswordUtils.checkNotNull(tile, Globals.UPDATE_LETTER_ERROR + "Cannot update " +
                "a tile to null");
        this.tile = tile;
    }

    /**
     * Getter for tile
     *
     * @return the tile
     */
    public Tile getTile() {
        return tile;
    }

    /**
     * {@inheritDoc}
     */
    public String getAction() {
        return Globals.UPDATE_LETTER;
    }
}
